<!DOCTYPE html>
<html class="um landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px">
    <head>
        <title></title>
        <meta charset="utf-8">
        <meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
        <link rel="stylesheet" href="css/fonts/font-awesome.min.css">
        <link rel="stylesheet" href="css/ui-box.css">
        <link rel="stylesheet" href="css/ui-base.css">
        <link rel="stylesheet" href="css/ui-color.css">
        <link rel="stylesheet" href="css/appcan.icon.css">
        <link rel="stylesheet" href="css/appcan.control.css">
        <link rel="stylesheet" href="css/media.css"/>
        <link rel="stylesheet" href="css/base.css"/>
    </head>
    <style>
      .hide {
            overflow: hidden; /*自动隐藏文字*/
            text-overflow: ellipsis;/*文字隐藏后添加省略号*/
            white-space: nowrap;/*强制不换行*/
        }   
        #decompressingFile{
         display: none;
         z-index: 9999;
         width: 90%;
         background: white;
         margin: 0 auto;
         
         border-radius: .3em;
         box-shadow:0 0 .2em #C1C1C1;
        }
        #decompressingFile>ul{
          overflow: scroll;  
          max-height:15em;
        }
        .bc08273E{
         background-color: #333333;   
        }
        .b_r50{
         border-radius: 50%;
        }
        .bcred{
         background: red;   
        }
        .cwhite{
         color: white;  
        }
    </style>
    <body class="um-vp bc-bg" ontouchstart>
      <div id="content" class="ub-f1 tx-l" style="background-color: white; height: 100%; overflow-x: hidden;">
            <h2 id="title1" class="tx-c" style="color:red; border-bottom: 1px solid black;padding-bottom: .5em;padding-top: .5em;width:98%;margin: 0 auto;"></h2>
            <article id="text" class="fs10" style="width:95%;height: auto;background-color: white;padding-bottom: .5em; margin: 0 auto;"></article>
            
        </div>
        <div style="width: 100%;position: fixed;top:20%;">
        <div id="decompressingFile">
             
            <div class="h20 bc08273E ub ub-pe cwhite">
                                             
                <div class="h20 w40 lh20 tx-c" onclick="hideListFile()">关闭</div>
               
              </div>
              <ul>
                   
              </ul>    
            </div>
       </div>    
    </body>
    <script src="js/appcan.js"></script>
    <script src="js/appcan.control.js"></script>
    <script src="js/main.js"></script>
    <script src="js/fileDownLoad.js"></script>
    </body>
    <script>
      appcan.ready(function() {
            

            var detailInfoObj = JSON.parse(appcan.locStorage.getVal('detailInfoObj'));
      

            $('#title1').text(detailInfoObj.contentInfo.contentName);
            $('#text').html(detailInfoObj.contentInfo.contentDesc);
            //console.log($('#text').find('span'));
            $('#text').find('span').css('font-size', '1em');
            $('#text').find('p').css('font-size', '1em');
            $('#text').find('img').css('width', '100%');
            $('#text').find('a').each(function(){
                
               var url = $(this).attr('href'); 
               $(this).attr('href','javascript:void(0);');
               var moduleId = appcan.locStorage.getVal('title1');
               $(this).click(function(event) {
                //IC.talkingDataCount("部门通告","0010");   
                   //取消事件的默认动作
                   event.preventDefault();
                   downloadFileByNetworkUrl(url, moduleId);
                
        
              /*
               * exDownloaderMgr.download()
               *参数名称                          参数类型       是否必选                           说明
               *downloader  Object   是                  由create接口创建的下载对象
               *serverURL   String   是                  服务器地址
               *savePath    String   是                  本地保存地址
               *mode        Number   是                  是否支持断点续传,0:不支持,1:支持
               *cb         Function  是                  下载进度回调,详见下
               * 
               */
     
                 
            });
            
         });
             
      });     
          
          function downloadFileByNetworkUrl(url, moduleId) {
                    var encodeUrl =  encodeURI(url);
                    //var userId = 'wangying69';
                    var userId = localStorage['MU30-lOGIN-USRNAME'];
                    //地址长度
                    var len = url.length;
                    var beg = url.lastIndexOf(".");
                    //文件类型
                    var file_type = url.substring(beg + 1, len);
                    //文件名称
                    var file_name = url.substring(url.lastIndexOf('_') + 1, beg);
                    //alert(file_type);
                    //服务器路径转换成本地路径
                    var localPath = "";
                    //解压后的文件路径
                    var unZipPath = "";
                    //唯一标识
                    var date = new Date();
                    var downOpCode = date.getMilliseconds();
           
                    
                    //下载路径和解压路径转换
                    if (isAndroid) {//Android目录
                        localPath = "file:///sdcard/Download/" + userId + "/" + moduleId + "/" + file_name + "." + file_type;
                        unZipPath = "file:///sdcard/Download/" + userId + "/" + moduleId+ "/"+file_name;
                    } else {//ios目录
                        localPath = "wgt://Download/" + userId + "/" + moduleId + "/" + file_name + "." + file_type;
                        unZipPath = "wgt://Download/" + userId + "/" + moduleId + "/"+file_name;
                      
                    }
                    
                               
                
                    /*  
                     * 
                     * status       fileSize   percent
                     * -下载状态 0      文件大小                     下载进度
                     * -下载中 1
                     * -下载完成 2
                     * -下载发生错误
                     */ 
                     
                    //下载状态改变的监听方法 
                    uexDownloaderMgr.onStatus = function(opCode, fileSize, percent, status) {

                        switch (status) {
                        case 0:
                            //下载中
                             uexWindow.toast(0,5,'下载进度：'+percent+'%' ,0);
                             break;
                        case 1:
                        
                          
                          //关闭提示框  
                           uexWindow.closeToast();
                          //回调打开
                           createDocumentReader(file_type,localPath,unZipPath);
                          //关闭下载对象
                           uexDownloaderMgr.closeDownloader(opCode);
                            break;
                        case 2:
                            
                            uexDownloaderMgr.closeDownloader(opCode);
                            uexWindow.closeToast();
                            //下载失败
                            
                            break;
                        }
                    }
                    
                    // 创建下载对象会回调
                    uexDownloaderMgr.cbCreateDownloader = function(opCode, dataType, data) {
                        //alert(data+'==='+dataType+'==='+opCode);
                        if (data == 0) {
                            //alert(downOpCode+'=='+url+'=='+localPath); 
                            uexDownloaderMgr.download(opCode, encodeUrl, localPath,"1");                            
                          
                        } else {
                            
                            uexWindow.toast('0','5', '创建下载失败...',2000);  
                        }
                    }
                    
                     //解压方法的回调，0--成功，1--失败
                    uexZip.cbUnZip = function(opCode, dataType, data) {
                        //alert(dataType+'--->'+data);
                        if(data == 0){
                        uexWindow.toask('0','5', '解压成功',2000);
                        uexFileMgr.getFileListByPath(unZipPath);    
                           
                        }else{
                            
                          uexWindow.toask('0','5', '解压失败',2000); 
                        }
                    }
                    
                    uexRarUncompressExe.cbUncompress = function(opCode, dataType,data){
                    if(data == 1){
                         uexWindow.toask('0','5', '解压失败',2000); 
                        }else{
                        uexWindow.toask('0','5', '解压成功',2000);
                        uexFileMgr.getFileListByPath(unZipPath);      //1
                       
                     }    
                    }  
                    
                    // 获取某路径下的所有文件             
                    uexFileMgr.cbGetFileListByPath = function(downOpCode, dataType, data){
                      //alert(data);  
                      if(data){
                      //文件信息数据
                      var filePatArr = JSON.parse(data);
                      var tpl = "";
                      filePatArr.forEach(function(item){
                          tpl += '<li class="fileType" style="border-bottom:1px solid #C1C1C1;" data="'+item.filePath+'"><p class="h20 lh20 hide fs10 pl5 tx-l">'+item.fileName+'</p></li>';   
                      });
                      $("#decompressingFile>ul").html(tpl);
                      $("#decompressingFile").css('display','block');
                      //打开文件目录
                      $(".fileType").each(function(){
                          $(this).click(function(){
                          //IC.talkingDataCount("部门通告","0010");
                           var file = $(this).attr('data');
                           if(file.indexOf(".") == -1){
                              uexFileMgr.getFileListByPath(filePatArr[0].filePath);  
                           }else{
                              uexDocumentReader.openDocumentReader($(this).attr('data'));   
                           }   
                             
                       });    
                    });
                 }
                 else{
                      //alert('文件无法打开');
                      uexWindow.toast(0,5,'文件无法打开' ,2000);
                 }
               }       
                    
 
                    // 根据路径判断文件是否存在的回调方法  1--存在，0--不存在
                    uexFileMgr.cbIsFileExistByPath = function(opId, dataType, data) {
                        //IC.talkingDataCount("部门通告","0010");
                        //alert(data+'=='+dataType+'=='+opId);
                        if (data == 1) {
                           
                            //先判断文件类型压缩文件先解压后打开。文件可以直接打开
                            if(file_type == "rar"){
                              uexFileMgr.getFileListByPath(unZipPath);
                            }else if(file_type == "zip"){
                              uexFileMgr.getFileListByPath(unZipPath);  
                            }else{
                              uexDocumentReader.openDocumentReader(localPath);
                            }
                            
                           
                        } else {
                            //创建下载对象
                            var headJson = '{"Content-type":"application/json;charset=utf-8"}';
                            uexDownloaderMgr.setHeaders(downOpCode, headJson);
                            uexDownloaderMgr.createDownloader(downOpCode);
                            
                        }
                    }
                    
                    // 根据路径判断文件是否存在
                    uexFileMgr.isFileExistByPath(downOpCode, localPath);
                }
            
            //判断文件类型，压缩文件先解压。文件直接打开
            function createDocumentReader(fileType, savePath, unzipPath) {
                //IC.talkingDataCount("部门通告","0010");
                if (fileType == "zip") {
                    //alert(unzipPath);
                    uexZip.unzip(savePath, unzipPath);
                }else if(fileType == "rar"){
                    uexRarUncompressExe.Uncompress(savePath, unzipPath,"ture");
                } else {
                    uexDocumentReader.openDocumentReader(savePath);
                }
            }  
            //隐藏文件目录                
            function hideListFile(){
                //IC.talkingDataCount("部门通告","0010");
              $("#decompressingFile").css("display","none");  
            }
    </script>
</html>
